import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), vueDevTools()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    proxy: {
      '/t1owwrrrj.hn-bkt.clouddn.com': {
        target: 'http://t1owwrrrj.hn-bkt.clouddn.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/t1owwrrrj.hn-bkt.clouddn.com/, ''),
      },
      '^/users/t1owwrrrj\\.hn-bkt\\.clouddn\\.com/.*\\.(png|jpg|jpeg|gif|webp|bmp)$': {
        target: 'http://t1owwrrrj.hn-bkt.clouddn.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/users\/t1owwrrrj\.hn-bkt\.clouddn\.com/, ''),
      },
      '^/categories/t1owwrrrj\\.hn-bkt\\.clouddn\\.com/.*\\.(png|jpg|jpeg|gif|webp|bmp)$': {
        target: 'http://t1owwrrrj.hn-bkt.clouddn.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/categories\/t1owwrrrj\.hn-bkt\.clouddn\.com/, ''),
      },
    },
  },
})
